package com.neusoft.neuiotms.dcom.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neusoft.bizcore.web.bean.TreeBean;
import com.neusoft.neuiotms.common.dto.DictionaryDTO;
import com.neusoft.neuiotms.common.service.DictionaryService;
import com.neusoft.neuiotms.dcom.service.ServiceTypeService;

@Service
public class ServiceTypeServiceImpl implements ServiceTypeService {

    @Autowired
    private DictionaryService dictionaryService;

    String serviceTypeCode = "worktype";

    @Override
    public List<TreeBean> index() {
        final List<TreeBean> result = new ArrayList<>();
        final List<DictionaryDTO> list = this.dictionaryService.findByDictionaryType(this.serviceTypeCode);

        list.stream().map(l -> {
            final TreeBean tree = new TreeBean();
            tree.setCode(l.getCode());
            tree.setTitle(l.getText());
            final List<DictionaryDTO> items = this.dictionaryService.findByDictionaryType(l.getCode());
            items.stream().map(k -> {
                final TreeBean item = new TreeBean();
                item.setCode(k.getCode());
                item.setTitle(k.getText());
                return item;
            }).forEach(tree.getChildren()::add);

            return tree;
        }).forEach(result::add);

        return result;
    }

}
